package com.ymatou.userservice.testcase;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.userservice.parameter.WeiXinUserRequestDtoBean;
import com.ymatou.userservice.service.WeiXinUserRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.UserCallService;
import com.ymttest.database.model.YmtUsers;
import com.ymttest.database.mongo.UserTokenWapper;
import com.ymttest.database.sqlwapper.LoginHistoryWapper;
import com.ymttest.database.sqlwapper.YmtUsersWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.AppTypeChannel;
import com.ymttest.utils.constant.ECode;
import com.ymttest.utils.constant.ThirdPartyType;
/**
*创建YMT微信用户接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_WeiXinUserRequestDto{
	private static WeiXinUserRequestDtoBean regBean;
	private static WeiXinUserRequestDtoCall regCall;
	private YmtUsersWapper userWapper;
	private UserTokenWapper userTokenWapper;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("微信用户注册 ");
	}

	@Before
	public void caseUp() throws Exception {
		regBean = new WeiXinUserRequestDtoBean();
		regCall = new WeiXinUserRequestDtoCall();
		userWapper = new YmtUsersWapper();
		userTokenWapper = new UserTokenWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(regCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

//	1.第三方账号不存在，输入手机号没有关联码头账号 => 创建新的码头账号
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_WeiXinUserRequestDto_001() {
		Logger.start(true,"微信账号第一次授权,创建用户成功");
		try {
			String unionId = "unionId_"+TestDataManager.getRandomNum(8);
			Logger.comment("微信账号第一次授权，检查需要绑定手机号");
			UserCallService.checkThirdPartyNeedBindMobile(unionId, ThirdPartyType.WEIXIN, ECode.USER_YES);
			
			Logger.comment("绑定手机号，注册微信账号");
			String phone = TestDataManager.getPhoneNum();
			UserCallService.checkMobileIsBindYmtUser(phone, "no");
			String openId = "openId_"+TestDataManager.getRandomNum(10);
			regBean.setCountry("China");
			regBean.setProvince("Shanghai");
			regBean.setCity("Shanghai");
			regBean.setClientIp("1.1.1.1");
			regBean.setHeadimgurl("");
			regBean.setName("WeiXiUser_"+TestDataManager.getRandomNum(5));
			regBean.setOId(openId);
			regBean.setRegSource("app");
			regBean.setSex("Femail");
			regBean.setTimeOut(new Date().getTime());
			regBean.setTSource("ios");
			regBean.setMobile(phone);
			regBean.setUnionId(unionId);
			regBean.setDeviceId(TestDataManager.getRandomUUID().toString());
			regBean.setEquimentid(TestDataManager.getRandomUUID().toString());
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setWeixinToken("weixintoken_"+TestDataManager.getRandomNum(4));
			regCall.setData(regBean);
			regCall.callService();
			Logger.verifyEquals("注册成功", regCall.getString("SuccessMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.SUCCESS, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", regCall.getString("Success"), "验证是否成功");
			
			Logger.comment("和数据库进行数据校验");
			Thread.sleep(1000);
			Map user = userWapper.getThirdPartyByThirdPartyId("Ymt_User_At_Wexin_Identify", "sUnionId", unionId);
			int userId = (Integer)user.get("iYmtUserId");
			Map userToken = userTokenWapper.getUserTokenByUid(userId);
			Logger.verifyEquals(userToken.get("uId"), ((Double)regCall.getResult().get("UserId")).intValue(), "验证用户ID");
			Logger.verifyEquals(userToken.get("sId"), regCall.getResult().get("Token"), "验证Token信息");
			Logger.verifyEquals("new", regCall.getResult().get("Remark"), "验证Remark信息");
			Logger.verifyEquals("Success", regCall.getResult().get("VerifyCode"), "验证凭据");
			Thread.sleep(1000);
			Map m=new HashMap<>();
			m.put("Uid", userId);
			Map history=new LoginHistoryWapper().selectUserRegHistoryByUid(m).get(0);
			Logger.debug(history);
			Logger.verifyEquals(regBean.getDeviceId(), history.get("DeviceId"), "验证凭据DeviceId");
			Logger.verifyEquals(regBean.getName().toLowerCase(), history.get("LoginId").toString(), "验证凭据LoginId");
			Logger.verifyEquals(regBean.getMobile(), history.get("Mobile"), "验证凭据Mobile");
			Logger.verifyEquals(regBean.getClientIp(), history.get("ClientIp"), "验证凭据ClientIp");
			Logger.verifyEquals("WeiXin", history.get("ChannelSource"), "验证凭据ChannelSource");
			//1 App
			Logger.verifyEquals("App", history.get("RegSource"), "验证凭据RegSource");
			Logger.verifyEquals(regBean.getEquimentid(), history.get("Equimentid"), "验证凭据CookieId");
			// Ymt_User_At_Wexin_Identify
			// mongo ulc_201406
			// Ymt_Users
			YmtUsers user1 = new YmtUsersWapper().getYmtUsers(userId);
			//验证cellphone
			Logger.verifyEquals(phone, user1.getScellphone(), "验证cellphone");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_WeiXinUserRequestDto_002() {
		Logger.start(true,"用户已存在（非第一次授权），则用户直接登录成功");
		try {
			Map thirdParty = userWapper.selectOneThirdPartyBindPhone("iYmtUserId", "sUnionId", "Ymt_User_At_Wexin_Identify");
			String unionId = thirdParty.get("sUnionId").toString();
			String openId = "openId_"+TestDataManager.getRandomNum(4);
			String sAccountName = thirdParty.get("sAccountName").toString();
			
			regBean.setCountry("China");
			regBean.setProvince("Shanghai");
			regBean.setCity("Shanghai");
			regBean.setClientIp("1.1.1.1");
			regBean.setHeadimgurl("");
			regBean.setName("WeiXiUser_"+TestDataManager.getRandomNum(5));
			regBean.setOId(openId);
			regBean.setRegSource("app");
			regBean.setSex("Femail");
			regBean.setTimeOut(new Date().getTime());
			regBean.setTSource("android");
			regBean.setUnionId(unionId);
			regBean.setMobile(sAccountName);
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setWeixinToken("weixintoken_"+TestDataManager.getRandomNum(4));
			regCall.setData(regBean);
			regCall.callService();
			Logger.verifyEquals("登录成功", regCall.getString("SuccessMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.SUCCESS, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", regCall.getString("Success"), "验证是否成功");
			Logger.verifyIsNull( regCall.getResult().get("Remark"), "验证Remark信息");
			Logger.verifyEquals("Success", regCall.getResult().get("VerifyCode"), "验证凭据");
			
			Map user = userWapper.getThirdPartyByThirdPartyId("Ymt_User_At_Wexin_Identify", "sUnionId", unionId);
			int userId = (Integer)user.get("iYmtUserId");
			Map userToken = userTokenWapper.getUserTokenByUid(userId);
			Logger.comment("对比数据库信息");
			Logger.verifyEquals(userToken.get("uId"), ((Double)regCall.getResult().get("UserId")).intValue(), "验证用户ID");
			Logger.verifyEquals(userToken.get("sId"), regCall.getResult().get("Token"), "验证Token信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_WeiXinUserRequestDto_003() {
		Logger.start(false,"手机号已绑定过其他微信账号,继续用该手机注册微信账号，失败");
		try {
			String phone = TestDataManager.getPhoneNum();
			String oldunionId = "weixin_"+TestDataManager.getRandomNum(10);
			UserCallService.regByWeiXin(oldunionId, phone, true, "注册成功");
			
			String unionId = "weixinnew_"+TestDataManager.getRandomNum(10);
			Logger.comment("微信账号第一次授权，检查需要绑定手机号");
			UserCallService.checkThirdPartyNeedBindMobile(unionId, ThirdPartyType.WEIXIN, ECode.USER_YES);
			
			Logger.comment("验证手机号绑定过微信账号");
			UserCallService.checkMobileIsBindThirdParty(phone, unionId, ThirdPartyType.WEIXIN, ECode.USER_YES);
			
			String openId = "openId_"+TestDataManager.getRandomNum(4);
			Logger.comment("继续使用该手机号，注册微信账号");
			regBean.setCountry("China");
			regBean.setProvince("Shanghai");
			regBean.setCity("Shanghai");
			regBean.setClientIp("1.1.1.1");
			regBean.setHeadimgurl("");
			regBean.setName("WeiXiUser_"+TestDataManager.getRandomNum(5));
			regBean.setOId(openId);
			regBean.setRegSource("app");
			regBean.setSex("Femail");
			regBean.setTimeOut(new Date().getTime());
			regBean.setTSource("android");
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setUnionId(unionId);
			regBean.setMobile(phone);
			regBean.setWeixinToken("weixintoken_"+TestDataManager.getRandomNum(4));
			regCall.setData(regBean);
			regCall.callService();
			
			Logger.verifyEquals("false", regCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals(ECode.ERROR400, regCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("该手机号码已经绑定过微信了，换一个试试吧~", regCall.getString("LastErrorMessage"), "验证Msg信息");
			Logger.verifyEquals("AlreadyUnionMatouUser", regCall.getResult().get("VerifyCode"), "验证verifyCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
//	2.第三方账号不存在，输入手机号有码头账号 => 绑定第三方账号
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_WeiXinUserRequestDto_004() {
		Logger.start(true,"手机号已经注册过码头账号，选择继续绑定");
		try {
			Logger.comment("手机注册洋码头账号");
			String phone = TestDataManager.getPhoneNum();
			Map user = UserCallService.registerUser(null, phone,null);
			
			Logger.comment("检查手机绑定了码头账号");
			UserCallService.checkMobileIsBindYmtUser(phone, ECode.USER_YES);
			
			String unionId = "weixinReg_"+TestDataManager.getRandomNum(10);
			Logger.comment("验证手机号是否绑定过微信账号");
			UserCallService.checkMobileIsBindThirdParty(phone, unionId, ThirdPartyType.WEIXIN, ECode.USER_NO);
			
			String openId = "openId_"+TestDataManager.getRandomNum(9);
			Logger.comment("继续使用该手机号，注册微信账号");
			regBean.setCountry("China");
			regBean.setProvince("Shanghai");
			regBean.setCity("Shanghai");
			regBean.setClientIp("1.1.1.1");
			regBean.setHeadimgurl("");
			regBean.setName("WeiXiUser_"+TestDataManager.getRandomNum(5));
			regBean.setOId(openId);
			regBean.setRegSource("app");
			regBean.setSex("Femail");
			regBean.setTimeOut(new Date().getTime());
			regBean.setTSource("android");
			regBean.setUnionId(unionId);
			regBean.setMobile(phone);
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setWeixinToken("weixintoken_"+TestDataManager.getRandomNum(4));
			regCall.setData(regBean);
			regCall.callService();

			Logger.verifyEquals("登录成功", regCall.getString("SuccessMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.SUCCESS, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", regCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals((Integer)user.get("userId"), ((Double)regCall.getResult().get("UserId")).intValue(), "验证绑定前后是同一个用户");
			
			Logger.comment("检查该用户绑定了微信账号");
			List<Map> thirdParty = new ArrayList<Map>();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, unionId, true);
			UserCallService.checkThirdPartyBindYmt((Integer)user.get("userId"), thirdParty);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_WeiXinUserRequestDto_005() {
		Logger.start(true,"用户绑定了A微信账号->解绑A微信账号->绑定B微信账号(手机号与A相同)->绑定成功");
		try {
			String phone = TestDataManager.getPhoneNum();
			Logger.comment("注册码头账号");
			UserCallService.registerUser(null, phone,null);
			
			Logger.comment("绑定了A微信账号");
			String unionIdA = "unbindweixin_"+TestDataManager.getRandomNum(10);
			Map user = UserCallService.regByWeiXin(unionIdA, phone, true, "登录成功");
			
			Logger.comment("绑定B微信账号(手机号与A相同)");
			String unionIdB = "unbindweixin_"+TestDataManager.getRandomNum(10); 
			UserCallService.regByWeiXin(unionIdB, phone, false, "该手机号码已经绑定过微信了，换一个试试吧~");
			
			int userId = ((Double)user.get("userId")).intValue();
			Logger.comment("解绑A微信账号");
			Map result = UserCallService.unbindThirdParty(userId, unionIdA, ThirdPartyType.WEIXIN);
			Logger.verifyEquals(200d, result.get("ResponseCode"), "验证Code");
			Logger.verifyEquals(true, result.get("Success"), "验证是否成功");
			Logger.verifyEquals("ok", result.get("Result"), "验证Msg信息");
			
			Logger.comment("再次绑定B微信账号(手机号与A相同)");
			UserCallService.regByWeiXin(unionIdB, phone, true, "登录成功");
			
			Logger.comment("验证用户的绑定情况");
			List<Map> thirdParty = new ArrayList<Map>();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, unionIdA, false);
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, unionIdB, true);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_WeiXinUserRequestDto_006() {
		Logger.start(true,"输入已关联过的用户(openId和UnionId已存在) ，则用户直接登录成功");
		try {
			String unionId = "unionId_"+TestDataManager.getRandomNum(20);
			Logger.comment("微信账号第一次授权，检查需要绑定手机号");
			UserCallService.checkThirdPartyNeedBindMobile(unionId, ThirdPartyType.WEIXIN, null);
			
			Logger.comment("绑定手机号，注册微信账号");
			String phone = TestDataManager.getPhoneNum();
			UserCallService.checkMobileIsBindYmtUser(phone, "no");
			String openId = "openId_"+TestDataManager.getRandomNum(10);
			regBean.setCountry("China");
			regBean.setProvince("Shanghai");
			regBean.setCity("Shanghai");
			regBean.setClientIp("1.1.1.1");
			regBean.setHeadimgurl("");
			regBean.setName("WeiXiUser_"+TestDataManager.getRandomNum(5));
			regBean.setOId(openId);
			regBean.setRegSource("app");
			regBean.setSex("Femail");
			regBean.setTimeOut(new Date().getTime());
			regBean.setTSource("ios");
			regBean.setMobile(phone);
			regBean.setUnionId(unionId);
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setWeixinToken("weixintoken_"+TestDataManager.getRandomNum(4));
			regCall.setData(regBean);
			regCall.callService();
			Logger.comment("微信账号已经授权，用户直接登录");
			regCall.callService();	
			int uid= ((Double)regCall.getResult().get("UserId")).intValue();
			Logger.verifyEquals("登录成功", regCall.getString("SuccessMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.SUCCESS, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", regCall.getString("Success"), "验证是否成功");
			Map userToken = userTokenWapper.getUserTokenByUid(uid);
			
			Logger.verifyEquals(userToken.get("uId"), ((Double)regCall.getResult().get("UserId")).intValue(), "验证用户ID");
			Logger.verifyEquals(userToken.get("sId"), regCall.getResult().get("Token"), "验证Token信息");
			Logger.verifyIsNull(regCall.getResult().get("Remark"), "验证Remark信息");
			Logger.verifyEquals("Success", regCall.getResult().get("VerifyCode"), "验证凭据");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_WeiXinUserRequestDto_007() {
		Logger.start(false,"不输入Open Id，用户创建失败");
		try {
			regBean.setCountry("China");
			regBean.setProvince("Shanghai");
			regBean.setCity("Shanghai");
			regBean.setClientIp("1.1.1.1");
			regBean.setHeadimgurl("");
			regBean.setName("WeiXiUser_"+TestDataManager.getRandomNum(5));
			regBean.setRegSource("app");
			regBean.setSex("Femail");
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setTimeOut(new Date().getTime());
			regBean.setTSource("android");
			regBean.setUnionId("unionId_"+TestDataManager.getRandomNum(4));
			regBean.setWeixinToken("weixintoken_"+TestDataManager.getRandomNum(4));
			
			regCall.setData(regBean);
			regCall.callService();			
			Logger.verifyEquals("false", regCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals(ECode.ERROR400, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("微信OpenId不能为空", regCall.getString("LastErrorMessage"), "验证返回的Message信息");
			Logger.verifyEquals(-1d, regCall.getResult().get("UserId"), "验证用户ID");
			Logger.verifyIsNull(regCall.getResult().get("Token"), "验证Token信息");
			Logger.verifyEquals("WeixinOpenIdIsEmpty", regCall.getResult().get("VerifyCode"), "验证凭据");
			Logger.verifyIsNull(regCall.getResult().get("Remark"), "验证remark信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_WeiXinUserRequestDto_008(){
		Logger.start(true,"不输入微信Token，注册成功");
		try {
			String openId = "openId_"+TestDataManager.getRandomNum(4);
			regBean.setCountry("China");
			regBean.setProvince("Shanghai");
			regBean.setCity("Shanghai");
			regBean.setClientIp("1.1.1.1");
			regBean.setHeadimgurl("");
			regBean.setName("WeiXiUser_"+TestDataManager.getRandomNum(5));
			regBean.setOId(openId);
			regBean.setRegSource("app");
			regBean.setSex("Femail");
			regBean.setTimeOut(new Date().getTime());
			regBean.setTSource("android");
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setMobile(TestDataManager.getPhoneNum());
			regBean.setUnionId("unionId_"+TestDataManager.getRandomNum(10));
			regCall.setData(regBean);
			regCall.callService();	
			
			Logger.verifyEquals("注册成功", regCall.getString("SuccessMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.SUCCESS, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", regCall.getString("Success"), "验证是否成功");
			
			Thread.sleep(1000);
			Map user = userWapper.selectUserAtWeiXinByOpenId(openId);
			int userId = (Integer)user.get("iYmtUserId");
			Map userToken = userTokenWapper.getUserTokenByUid(userId);
			Logger.verifyEquals(userToken.get("uId"), ((Double)regCall.getResult().get("UserId")).intValue(), "验证用户ID");
			Logger.verifyEquals(userToken.get("sId"), regCall.getResult().get("Token"), "验证Token信息");
			Logger.verifyEquals("new", regCall.getResult().get("Remark"), "验证Remark信息");
			Logger.verifyEquals("Success", regCall.getResult().get("VerifyCode"), "验证凭据");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_WeiXinUserRequestDto_009(){
		Logger.start(false,"不输入UnionId，用户创建失败");
		try {
			String openId = "openId_"+TestDataManager.getRandomNum(4);
			regBean.setCountry("China");
			regBean.setProvince("Shanghai");
			regBean.setCity("Shanghai");
			regBean.setClientIp("1.1.1.1");
			regBean.setHeadimgurl("");
			regBean.setName("WeiXiUser_"+TestDataManager.getRandomNum(5));
			regBean.setOId(openId);
			regBean.setRegSource("app");
			regBean.setSex("Femail");
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setTimeOut(new Date().getTime());
			regBean.setMobile(TestDataManager.getPhoneNum());
			regBean.setTSource("android");
			regBean.setWeixinToken("weixintoken_"+TestDataManager.getRandomNum(4));
			
			regCall.setData(regBean);
			regCall.callService();			
			Logger.verifyEquals("false", regCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals(ECode.ERROR400, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("微信unionid不能为空", regCall.getString("LastErrorMessage"), "验证返回的Message信息");
			Logger.verifyEquals(-1d, regCall.getResult().get("UserId"), "验证用户ID");
			Logger.verifyIsNull(regCall.getResult().get("Token"), "验证Token信息");
			Logger.verifyEquals("WeiXinUnionIdIsEmpty", regCall.getResult().get("VerifyCode"), "验证凭据");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_WeiXinUserRequestDto_010() {
		Logger.start(true,"用户绑定了A微信账号->解绑A微信账号->绑定B微信账号(微信号与A相同，手机号与A不同，手机未绑定过码头账号)->绑定成功");
		try {
			String phone = TestDataManager.getPhoneNum();
			Logger.comment("注册码头账号");
			UserCallService.registerUser(null, phone,null);
			
			Logger.comment("绑定了A微信账号");
			String weixinA = "unbindali_"+TestDataManager.getRandomNum(10);
			Map user = UserCallService.regByWeiXin(weixinA, phone, true, "登录成功");
			int userId = ((Double)user.get("userId")).intValue();
			List<Map> thirdParty = new ArrayList<Map>();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, weixinA, true);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
			Thread.sleep(1000);
			Logger.comment("解绑A微信账号");
			Map result = UserCallService.unbindThirdParty(userId, weixinA, ThirdPartyType.WEIXIN);
			Logger.verifyEquals(200d, result.get("ResponseCode"), "验证Code");
			Logger.verifyEquals(true, result.get("Success"), "验证是否成功");
			Logger.verifyEquals("ok", result.get("Result"), "验证Msg信息");
			thirdParty.clear();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, weixinA, false);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
			
			Logger.comment("绑定B微信账号(微信号与A相同，手机号与A不同)");
			String phoneB = TestDataManager.getPhoneNum();
			UserCallService.checkThirdPartyNeedBindMobile(weixinA, ThirdPartyType.WEIXIN, ECode.USER_YES);
			UserCallService.checkMobileIsBindThirdParty(phoneB, weixinA,  ThirdPartyType.WEIXIN, ECode.USER_NO);
			Map bindUser = UserCallService.regByWeiXin(weixinA, phoneB, true, "注册成功");
			int newUserId = ((Double)bindUser.get("userId")).intValue();
			Logger.verifyNotEquals(userId, newUserId, "验证创建了一个新用户");
			
			Logger.comment("验证新用户的绑定情况");
			thirdParty.clear();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, weixinA, true);
			UserCallService.checkThirdPartyBindYmt(newUserId, thirdParty);
			
			Logger.comment("验证老用户的绑定情况");
			thirdParty.clear();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, weixinA, false);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
//	5.第三方账号，已存在，已解绑，输入原来已绑定过的手机号 => 恢复码头账号和第三方账号绑定关系
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_WeiXinUserRequestDto_011() {
		Logger.start(true,"用户绑定了A微信账号->解绑A微信账号->绑定A微信账号->绑定成功");
		try {
			String phone = TestDataManager.getPhoneNum();
			Logger.comment("注册码头账号");
			UserCallService.registerUser(null, phone,null);
			
			Logger.comment("绑定了A微信账号");
			String weixinA = "unbindali_"+TestDataManager.getRandomNum(10);
			Map user = UserCallService.regByWeiXin(weixinA, phone, true, "登录成功");
			int userId = ((Double)user.get("userId")).intValue();
			List<Map> thirdParty = new ArrayList<Map>();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, weixinA, true);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
			
			Logger.comment("解绑A微信账号");
			Map result = UserCallService.unbindThirdParty(userId, weixinA, ThirdPartyType.WEIXIN);
			Logger.verifyEquals(200d, result.get("ResponseCode"), "验证Code");
			Logger.verifyEquals(true, result.get("Success"), "验证是否成功");
			Logger.verifyEquals("ok", result.get("Result"), "验证Msg信息");
			thirdParty.clear();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, weixinA, false);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
			
			Logger.comment("绑定A微信账号");
			UserCallService.checkThirdPartyNeedBindMobile(weixinA, ThirdPartyType.WEIXIN, ECode.USER_YES);
			UserCallService.checkMobileIsBindThirdParty(phone, weixinA,  ThirdPartyType.WEIXIN, ECode.USER_NO);
			Map bindUser = UserCallService.regByWeiXin(weixinA, phone, true, "登录成功");
			int newUserId = ((Double)bindUser.get("userId")).intValue();
			Logger.verifyEquals(userId, newUserId, "验证绑定前后是同一个用户");
			
			Logger.comment("验证用户的绑定情况");
			thirdParty.clear();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, weixinA, true);
			UserCallService.checkThirdPartyBindYmt(newUserId, thirdParty);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_WeiXinUserRequestDto_012() {
		Logger.start(true,"用户绑定了A微信账号->解绑A微信账号->绑定B微信账号(微信号与A相同，手机号与A不同，手机绑定过码头账号)->绑定成功");
		try {
			String phone = TestDataManager.getPhoneNum();
			Logger.comment("注册码头账号");
			UserCallService.registerUser(null, phone,null);
			
			Logger.comment("绑定了A微信账号");
			String weixinA = "unbindali_"+TestDataManager.getRandomNum(10);
			Map user = UserCallService.regByWeiXin(weixinA, phone, true, "登录成功");
			int userId = ((Double)user.get("userId")).intValue();
			List<Map> thirdParty = new ArrayList<Map>();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, weixinA, true);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
			
			Logger.comment("解绑A微信账号");
			Map result = UserCallService.unbindThirdParty(userId, weixinA, ThirdPartyType.WEIXIN);
			Logger.verifyEquals(200d, result.get("ResponseCode"), "验证Code");
			Logger.verifyEquals(true, result.get("Success"), "验证是否成功");
			Logger.verifyEquals("ok", result.get("Result"), "验证Msg信息");
			thirdParty.clear();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, weixinA, false);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
			
			Logger.comment("绑定B微信账号(微信号与A相同，手机号与A不同，手机绑定过码头账号)");
			String phoneB = TestDataManager.getPhoneNum();
			Map userB = UserCallService.registerUser(null, phoneB,null);
			UserCallService.checkThirdPartyNeedBindMobile(weixinA, ThirdPartyType.WEIXIN, ECode.USER_YES);
			UserCallService.checkMobileIsBindThirdParty(phoneB, weixinA,  ThirdPartyType.WEIXIN, ECode.USER_NO);
			UserCallService.checkMobileIsBindYmtUser(phoneB, "yes");
			Map bindUser = UserCallService.regByWeiXin(weixinA, phoneB, true, "登录成功");
			int newUserId = ((Double)bindUser.get("userId")).intValue();
			Logger.verifyEquals((Integer)userB.get("userId"), newUserId, "验证绑定到了新用户B");
			
			Logger.comment("验证新用户的绑定情况");
			thirdParty.clear();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, weixinA, true);
			UserCallService.checkThirdPartyBindYmt(newUserId, thirdParty);
			
			Logger.comment("验证老用户的绑定情况");
			thirdParty.clear();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIXIN, weixinA, false);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_WeiXinUserRequestDto_013() {
		Logger.start(false,"第三方用户已存在（非第一次授权）,绑定不同的手机号，则用户直接登录成功");
		try {
			Map thirdParty = userWapper.selectOneThirdPartyBindPhone("iYmtUserId", "sUnionId", "Ymt_User_At_Wexin_Identify");
			String unionId = thirdParty.get("sUnionId").toString();
			String openId = "openId_"+TestDataManager.getRandomNum(4);
			UserCallService.checkThirdPartyNeedBindMobile(unionId, ThirdPartyType.WEIXIN, ECode.USER_NO);
			
			regBean.setCountry("China");
			regBean.setProvince("Shanghai");
			regBean.setCity("Shanghai");
			regBean.setClientIp("1.1.1.1");
			regBean.setHeadimgurl("");
			regBean.setName("WeiXiUser_"+TestDataManager.getRandomNum(5));
			regBean.setOId(openId);
			regBean.setRegSource("app");
			regBean.setSex("Femail");
			regBean.setTimeOut(new Date().getTime());
			regBean.setTSource("android");
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setUnionId(unionId);
			regBean.setMobile(TestDataManager.getPhoneNum());
			regBean.setWeixinToken("weixintoken_"+TestDataManager.getRandomNum(4));
			regCall.setData(regBean);
			regCall.callService();
			Logger.verifyEquals("当前账号已绑定", regCall.getString("LastErrorMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.ERROR400, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("false", regCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("AlreadyUnionMatouUser", regCall.getResult().get("VerifyCode"), "验证凭据");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_WeiXinUserRequestDto_014() {
		Logger.start(false,"手机号已经注册过码头账号，第三方账号也绑定过码头账号，绑定失败");
		try {
			Logger.comment("手机注册洋码头账号");
			String phone = TestDataManager.getPhoneNum();
			Map user = UserCallService.registerUser(null, phone,null);
			
			Logger.comment("检查手机绑定了码头账号");
			UserCallService.checkMobileIsBindYmtUser(phone, ECode.USER_YES);
			
			Logger.comment("微信账号也绑定过其他码头账号");
			String unionId = "weixinReg_"+TestDataManager.getRandomNum(10);
			UserCallService.regByWeiXin(unionId, TestDataManager.getPhoneNum(), true, "注册成功");
			
			String openId = "openId_"+TestDataManager.getRandomNum(4);
			Logger.comment("继续使用该手机号，注册微信账号");
			regBean.setCountry("China");
			regBean.setProvince("Shanghai");
			regBean.setCity("Shanghai");
			regBean.setClientIp("1.1.1.1");
			regBean.setHeadimgurl("");
			regBean.setName("WeiXiUser_"+TestDataManager.getRandomNum(5));
			regBean.setOId(openId);
			regBean.setRegSource("app");
			regBean.setSex("Femail");
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setTimeOut(new Date().getTime());
			regBean.setTSource("android");
			regBean.setUnionId(unionId);
			regBean.setMobile(phone);
			regBean.setWeixinToken("weixintoken_"+TestDataManager.getRandomNum(4));
			regCall.setData(regBean);
			regCall.callService();

			Logger.verifyEquals("当前账号已绑定", regCall.getString("LastErrorMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.ERROR400, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("false", regCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("AlreadyUnionMatouUser", regCall.getResult().get("VerifyCode"), "验证凭据");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
//	3.第三方账号，已存在，已解绑，且输入的手机号没有关联码头账号 => 创建新的码头账号
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_WeiXinUserRequestDto_015() {
		Logger.start(true,"用户OpenId，UnionId已存在（是解绑状态），再用该微信账号绑定另一个手机号，返回注册成功");
		try {
			Logger.comment("注册微信账号");
			String unionReg = "RegUnion_"+TestDataManager.getRandomNum(7);
			String phoneReg = TestDataManager.getPhoneNum();
			Map userReg = UserCallService.regByWeiXin(unionReg, phoneReg, true, "注册成功");
			UserCallService.regByAli("aliTest_"+TestDataManager.getRandomNum(7), phoneReg, true, "登录成功");
			String openId = userReg.get("openId").toString();
			int userId = ((Double)userReg.get("userId")).intValue();
			
			Logger.comment("解绑微信账号");
			UserCallService.unbindThirdParty(userId, unionReg, ThirdPartyType.WEIXIN);
			
			Logger.comment("绑定另一个手机号");
			String phoneBind = TestDataManager.getPhoneNum();
			regBean.setCountry("China");
			regBean.setProvince("Shanghai");
			regBean.setCity("Shanghai");
			regBean.setClientIp("1.1.1.1");
			regBean.setHeadimgurl("");
			regBean.setName("WeiXiUser_"+TestDataManager.getRandomNum(5));
			regBean.setOId(openId);
			regBean.setRegSource("app");
			regBean.setSex("Femail");
			regBean.setTimeOut(new Date().getTime());
			regBean.setTSource("android");
			regBean.setUnionId(unionReg);
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setMobile(phoneBind);
			regBean.setWeixinToken("weixintoken_"+TestDataManager.getRandomNum(4));
			regCall.setData(regBean);
			regCall.callService();
			Logger.verifyEquals("注册成功", regCall.getString("SuccessMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.SUCCESS, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", regCall.getString("Success"), "验证是否成功");
			
			Map user = userWapper.getThirdPartyByThirdPartyId("Ymt_User_At_Wexin_Identify", "sUnionId", unionReg);
			int userIds = (Integer)user.get("iYmtUserId");
			Logger.verifyEquals(((Double)regCall.getResult().get("UserId")).intValue(), userIds, "验证用户ID");
			Thread.sleep(1000);
			Map userToken = userTokenWapper.getUserTokenByUid(userIds);
			Logger.comment("对比数据库信息");
			Logger.verifyEquals(userToken.get("uId"), ((Double)regCall.getResult().get("UserId")).intValue(), "验证用户ID");
			Logger.verifyEquals(userToken.get("sId"), regCall.getResult().get("Token"), "验证Token信息");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_WeiXinUserRequestDto_016() {
		Logger.start(true,"微信账号第一次授权,创建用户成功,账号长度大于20");
		try {
			String unionId = "unionId_"+TestDataManager.getRandomNum(20);
			Logger.comment("微信账号第一次授权，检查需要绑定手机号");
			UserCallService.checkThirdPartyNeedBindMobile(unionId, ThirdPartyType.WEIXIN, ECode.USER_YES);
			
			Logger.comment("绑定手机号，注册微信账号");
			String phone = TestDataManager.getPhoneNum();
			UserCallService.checkMobileIsBindYmtUser(phone, "no");
			String openId = "openId_"+TestDataManager.getRandomNum(10);
			regBean.setCountry("China");
			regBean.setProvince("Shanghai");
			regBean.setCity("Shanghai");
			regBean.setClientIp("1.1.1.1");
			regBean.setHeadimgurl("");
			regBean.setName("WeiXiUser_"+TestDataManager.getRandomNum(5));
			regBean.setOId(openId);
			regBean.setRegSource("app");
			regBean.setSex("Femail");
			regBean.setTimeOut(new Date().getTime());
			regBean.setTSource("ios");
			regBean.setMobile(phone);
			regBean.setUnionId(unionId);
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setWeixinToken("weixintoken_"+TestDataManager.getRandomNum(4));
			regCall.setData(regBean);
			regCall.callService();
			Logger.verifyEquals("注册成功", regCall.getString("SuccessMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.SUCCESS, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", regCall.getString("Success"), "验证是否成功");
			
			Logger.comment("和数据库进行数据校验");
			Thread.sleep(1000);
			Map user = userWapper.getThirdPartyByThirdPartyId("Ymt_User_At_Wexin_Identify", "sUnionId", unionId);
			int userId = (Integer)user.get("iYmtUserId");
			Map userToken = userTokenWapper.getUserTokenByUid(userId);
			Logger.verifyEquals(userToken.get("uId"), ((Double)regCall.getResult().get("UserId")).intValue(), "验证用户ID");
			Logger.verifyEquals(userToken.get("sId"), regCall.getResult().get("Token"), "验证Token信息");
			Logger.verifyEquals("new", regCall.getResult().get("Remark"), "验证Remark信息");
			Logger.verifyEquals("Success", regCall.getResult().get("VerifyCode"), "验证凭据");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_WeiXinUserRequestDto_017() {
		Logger.start(false,"微信账号第一次授权,创建用户失败,账号长度大于100");
		try {
			String unionId = "unionId_"+TestDataManager.getRandomNum(100);
			Logger.comment("微信账号第一次授权，检查需要绑定手机号");
			UserCallService.checkThirdPartyNeedBindMobile(unionId, ThirdPartyType.WEIXIN, ECode.USER_YES);
			
			Logger.comment("绑定手机号，注册微信账号");
			String phone = TestDataManager.getPhoneNum();
			UserCallService.checkMobileIsBindYmtUser(phone, "no");
			String openId = "openId_"+TestDataManager.getRandomNum(100);
			regBean.setCountry("China");
			regBean.setProvince("Shanghai");
			regBean.setCity("Shanghai");
			regBean.setClientIp("1.1.1.1");
			regBean.setHeadimgurl("");
			regBean.setName("WeiXiUser_"+TestDataManager.getRandomNum(100));
			regBean.setOId(openId);
			regBean.setRegSource("app");
			regBean.setSex("Femail");
			regBean.setTimeOut(new Date().getTime());
			regBean.setTSource("ios");
			regBean.setMobile(phone);
			regBean.setUnionId(unionId);
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setWeixinToken("weixintoken_"+TestDataManager.getRandomNum(4));
			regCall.setData(regBean);
			regCall.callService();
			String VerifyCode=regCall.getJsonObject().get("Result").getAsJsonObject().get("VerifyCode").getAsString();
			Logger.verifyEquals("LoginNameLengthError", VerifyCode, "验证返回的LoginNameLengthError信息");
			Logger.verifyEquals("500" ,regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("false", regCall.getString("Success"), "验证是否成功");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_WeiXinUserRequestDto_018() {
		Logger.start(true,"传入TokenSource为sellerapp用户注册成功JIRACONN-2123");
		try {
			String unionId = "unionId_"+TestDataManager.getRandomNum(8);
			Logger.comment("微信账号第一次授权，检查需要绑定手机号");
			UserCallService.checkThirdPartyNeedBindMobile(unionId, ThirdPartyType.WEIXIN, ECode.USER_YES);
			
			Logger.comment("绑定手机号，注册微信账号");
			String phone = TestDataManager.getPhoneNum();
			UserCallService.checkMobileIsBindYmtUser(phone, "no");
			String openId = "openId_"+TestDataManager.getRandomNum(10);
			regBean.setCountry("China");
			regBean.setProvince("Shanghai");
			regBean.setCity("Shanghai");
			regBean.setClientIp("1.1.1.1");
			regBean.setHeadimgurl("");
			regBean.setName("WeiXiUser_"+TestDataManager.getRandomNum(5));
			regBean.setOId(openId);
			regBean.setRegSource("app");
			regBean.setSex("Femail");
			regBean.setTimeOut(new Date().getTime());
			regBean.setTSource("ios");
			regBean.setMobile(phone);
			regBean.setUnionId(unionId);
			regBean.setDeviceId(TestDataManager.getRandomUUID().toString());
			regBean.setEquimentid(TestDataManager.getRandomUUID().toString());
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setWeixinToken("weixintoken_"+TestDataManager.getRandomNum(4));
			regBean.setTokenSource("sellerapp");
			regCall.setData(regBean);
			regCall.callService();
			Logger.verifyEquals("注册成功", regCall.getString("SuccessMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.SUCCESS, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", regCall.getString("Success"), "验证是否成功");
			
			Logger.comment("和数据库进行数据校验");
			Thread.sleep(1000);
			Map user = userWapper.getThirdPartyByThirdPartyId("Ymt_User_At_Wexin_Identify", "sUnionId", unionId);
			int userId = (Integer)user.get("iYmtUserId");
			Map userToken = userTokenWapper.getUserTokenByUid(userId);
			Logger.verifyEquals(userToken.get("uId"), ((Double)regCall.getResult().get("UserId")).intValue(), "验证用户ID");
			Logger.verifyEquals(userToken.get("sId"), regCall.getResult().get("Token"), "验证Token信息");
			Logger.verifyEquals("new", regCall.getResult().get("Remark"), "验证Remark信息");
			Logger.verifyEquals("Success", regCall.getResult().get("VerifyCode"), "验证凭据");
			Thread.sleep(1000);
			Map m=new HashMap<>();
			m.put("Uid", userId);
			Map history=new LoginHistoryWapper().selectUserRegHistoryByUid(m).get(0);
			Logger.debug(history);
			Logger.verifyEquals(regBean.getDeviceId(), history.get("DeviceId"), "验证凭据DeviceId");
			Logger.verifyEquals(regBean.getName().toLowerCase(), history.get("LoginId").toString(), "验证凭据LoginId");
			Logger.verifyEquals(regBean.getMobile(), history.get("Mobile"), "验证凭据Mobile");
			Logger.verifyEquals(regBean.getClientIp(), history.get("ClientIp"), "验证凭据ClientIp");
			Logger.verifyEquals("WeiXin", history.get("ChannelSource"), "验证凭据ChannelSource");
			//1 App
			Logger.verifyEquals("App", history.get("RegSource"), "验证凭据RegSource");
			Logger.verifyEquals(regBean.getEquimentid(), history.get("Equimentid"), "验证凭据CookieId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_WeiXinUserRequestDto_019() {
		Logger.start(true,"传入TokenSource为app用户注册成功JIRACONN-2123");
		try {
			String unionId = "unionId_"+TestDataManager.getRandomNum(8);
			Logger.comment("微信账号第一次授权，检查需要绑定手机号");
			UserCallService.checkThirdPartyNeedBindMobile(unionId, ThirdPartyType.WEIXIN, ECode.USER_YES);
			
			Logger.comment("绑定手机号，注册微信账号");
			String phone = TestDataManager.getPhoneNum();
			UserCallService.checkMobileIsBindYmtUser(phone, "no");
			String openId = "openId_"+TestDataManager.getRandomNum(10);
			regBean.setCountry("China");
			regBean.setProvince("Shanghai");
			regBean.setCity("Shanghai");
			regBean.setClientIp("1.1.1.1");
			regBean.setHeadimgurl("");
			regBean.setName("WeiXiUser_"+TestDataManager.getRandomNum(5));
			regBean.setOId(openId);
			regBean.setRegSource("app");
			regBean.setSex("Femail");
			regBean.setTimeOut(new Date().getTime());
			regBean.setTSource("ios");
			regBean.setMobile(phone);
			regBean.setUnionId(unionId);
			regBean.setDeviceId(TestDataManager.getRandomUUID().toString());
			regBean.setEquimentid(TestDataManager.getRandomUUID().toString());
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setWeixinToken("weixintoken_"+TestDataManager.getRandomNum(4));
			regBean.setTokenSource("app");
			regCall.setData(regBean);
			regCall.callService();
			Logger.verifyEquals("注册成功", regCall.getString("SuccessMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.SUCCESS, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", regCall.getString("Success"), "验证是否成功");
			
			Logger.comment("和数据库进行数据校验");
			Thread.sleep(1000);
			Map user = userWapper.getThirdPartyByThirdPartyId("Ymt_User_At_Wexin_Identify", "sUnionId", unionId);
			int userId = (Integer)user.get("iYmtUserId");
			Map userToken = userTokenWapper.getUserTokenByUid(userId);
			Logger.verifyEquals(userToken.get("uId"), ((Double)regCall.getResult().get("UserId")).intValue(), "验证用户ID");
			Logger.verifyEquals(userToken.get("sId"), regCall.getResult().get("Token"), "验证Token信息");
			Logger.verifyEquals("new", regCall.getResult().get("Remark"), "验证Remark信息");
			Logger.verifyEquals("Success", regCall.getResult().get("VerifyCode"), "验证凭据");
			Thread.sleep(1000);
			Map m=new HashMap<>();
			m.put("Uid", userId);
			Map history=new LoginHistoryWapper().selectUserRegHistoryByUid(m).get(0);
			Logger.debug(history);
			Logger.verifyEquals(regBean.getDeviceId(), history.get("DeviceId"), "验证凭据DeviceId");
			Logger.verifyEquals(regBean.getName().toLowerCase(), history.get("LoginId").toString(), "验证凭据LoginId");
			Logger.verifyEquals(regBean.getMobile(), history.get("Mobile"), "验证凭据Mobile");
			Logger.verifyEquals(regBean.getClientIp(), history.get("ClientIp"), "验证凭据ClientIp");
			Logger.verifyEquals("WeiXin", history.get("ChannelSource"), "验证凭据ChannelSource");
			//1 App
			Logger.verifyEquals("App", history.get("RegSource"), "验证凭据RegSource");
			Logger.verifyEquals(regBean.getEquimentid(), history.get("Equimentid"), "验证凭据CookieId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_WeiXinUserRequestDto_020() {
		Logger.start(false,"特殊字符用户名失败JIRACONN-2522");
		try {
			String unionId = "unionId_"+TestDataManager.getRandomNum(8);
			Logger.comment("绑定手机号，注册微信账号");
			String phone = TestDataManager.getPhoneNum();
			UserCallService.checkMobileIsBindYmtUser(phone, "no");
			String openId = "openId_"+TestDataManager.getRandomNum(10);
			regBean.setCountry("China");
			regBean.setProvince("Shanghai");
			regBean.setCity("Shanghai");
			regBean.setClientIp("1.1.1.1");
			regBean.setHeadimgurl("");
			regBean.setName("~!@#$%^&*");
			regBean.setOId(openId);
			regBean.setRegSource("app");
			regBean.setSex("Femail");
			regBean.setTimeOut(new Date().getTime());
			regBean.setTSource("ios");
			regBean.setMobile(phone);
			regBean.setUnionId(unionId);
			regBean.setDeviceId(TestDataManager.getRandomUUID().toString());
			regBean.setEquimentid(TestDataManager.getRandomUUID().toString());
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setWeixinToken("weixintoken_"+TestDataManager.getRandomNum(4));
			regCall.setData(regBean);
			regCall.callService();
			String VerifyCode=regCall.getJsonObject().get("Result").getAsJsonObject().get("VerifyCode").getAsString();
			Logger.verifyEquals("LoginNameContextError", VerifyCode, "验证返回的LoginNameContextError信息");
			Logger.verifyEquals(ECode.ERROR500, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("false", regCall.getString("Success"), "验证是否成功");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
//	6.第三方账号，已存在，未解绑，未绑定手机号，且输入的手机号没有关联码头账号 => 绑手机
	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_WeiXinUserRequestDto_021() {
		Logger.start(true,"第三方账号，已存在，未解绑，未绑定手机号，且输入的手机号没有关联码头账号 => 绑手机");
		try {
//			String phone = TestDataManager.getPhoneNum();
			String oldunionId = "unionIdnew_1359999459";
			String openId = "openId_"+TestDataManager.getRandomNum(10);
			Logger.comment("绑定手机号，注册微信账号RegSource_app,已绑定");
			regBean.setCountry("China");
			regBean.setProvince("Shanghai");
			regBean.setCity("Shanghai");
			regBean.setClientIp("1.1.1.1");
			regBean.setHeadimgurl("");
			regBean.setName("WeiXiUser_"+TestDataManager.getRandomNum(5));
			regBean.setRegSource("wap");
			regBean.setSex("Femail");
			regBean.setTimeOut(new Date().getTime());
			regBean.setTSource("ios");
//			regBean.setMobile(phone);
			regBean.setOId(openId);
			regBean.setUnionId(oldunionId);
			regBean.setDeviceId(TestDataManager.getRandomUUID().toString());
			regBean.setEquimentid(TestDataManager.getRandomUUID().toString());
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setWeixinToken("weixintoken_"+TestDataManager.getRandomNum(4));
			regCall.setData(regBean);
			regCall.callService();
			Logger.verifyEquals("登录成功", regCall.getString("SuccessMessage"), "验证返回的Message信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_WeiXinUserRequestDto_022() {
		Logger.start(true,"用户绑定了A微信账号->绑定B微信账号(手机号与A相同)->绑定失败");
		try {
			String phone = TestDataManager.getPhoneNum();
			String phone2 = TestDataManager.getPhoneNum();
			Logger.comment("注册码头账号");
			UserCallService.registerUser(null, phone,null);
			
			Logger.comment("绑定了A微信账号");
			String unionIdA = "unbindweixin_"+TestDataManager.getRandomNum(10);
			Map user = UserCallService.regByWeiXin(unionIdA, phone, true, "登录成功");
			
			
			
			Logger.comment("再次绑定B微信账号(手机号与A相同)");
			UserCallService.regByWeiXin(unionIdA, phone2, true, "当前账号已绑定");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_WeiXinUserRequestDto_023() {
		Logger.start(true,"微信老用户用户已存在（非第一次授权），则用户直接登录成功（数据修复）JIRACONN-7439");
		try {
			//select top 10 t1.* from Ymt_User_At_Wexin_Identify as t1 with(nolock) 
//			join ymt_users  as t2 with(nolock) 
//			on t1.iYmtUserId = t2.iUserId and t1.IsBind = 1
//			left join YMT_MOBILEPHONEACCOUNT as t3 with(nolock) 
//			on t1.iYmtUserId = t3.iUserId
//			where t3.iUserId is null;
//			Map thirdParty = userWapper.selectOneThirdPartyBindPhone("iYmtUserId", "sUnionId", "Ymt_User_At_Wexin_Identify");
			String unionId = "uidtest_"+TestDataManager.getRandomNum(8);
			String openId = "299809";
//			String sAccountName = thirdParty.get("sAccountName").toString();
			regBean.setMobile(TestDataManager.getPhoneNum());
			regBean.setCountry("China");
			regBean.setProvince("Shanghai");
			regBean.setCity("Shanghai");
			regBean.setClientIp("1.1.1.1");
			regBean.setHeadimgurl("");
			regBean.setName("WeiXiUser_"+TestDataManager.getRandomNum(5));
			regBean.setOId(openId);
			regBean.setRegSource("app");
			regBean.setTokenSource("app");
			regBean.setSex("Femail");
			regBean.setTimeOut(new Date().getTime());
			regBean.setTSource("android");
			regBean.setUnionId(unionId);
//			regBean.setMobile(sAccountName);
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setWeixinToken("weixintoken_"+TestDataManager.getRandomNum(4));
			regCall.setData(regBean);
			regCall.callService();
			Logger.verifyEquals("登录成功", regCall.getString("SuccessMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.SUCCESS, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", regCall.getString("Success"), "验证是否成功");
			Logger.verifyIsNull( regCall.getResult().get("Remark"), "验证Remark信息");
			Logger.verifyEquals("Success", regCall.getResult().get("VerifyCode"), "验证凭据");
			
			Map user = userWapper.getThirdPartyByThirdPartyId("Ymt_User_At_Wexin_Identify", "sUnionId", unionId);
			int userId = (Integer)user.get("iYmtUserId");
			Map userToken = userTokenWapper.getUserTokenByUid(userId);
			Logger.comment("对比数据库信息");
			Logger.verifyEquals(userToken.get("uId"), ((Double)regCall.getResult().get("UserId")).intValue(), "验证用户ID");
			Logger.verifyEquals(userToken.get("sId"), regCall.getResult().get("Token"), "验证Token信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
//	4.第三方账号，已存在，已解绑，且输入的手机号关联了码头账号 => 报异常


//

//			7.第三方账号，已存在，未解绑，绑定了手机号，输入的手机号没有关联码头账号 => 报异常
//			8.第三方账号，已存在，未解绑，绑定了手机号，输入的手机号是原手机号 => 正常登录
}